/*广告图片接口*/
import { get, post } from '@/utils/httpUtil'
import utils from '@/utils/utils'

const apis = {}

//广告图片列表数据查询
apis.fetchList = formData =>{
    return get('/ad/list', formData);
}

//根据id获取详情
apis.getDetail = id => {
	return get('/ad/detail?id='+id);
}

//更新或保存
apis.submitForm = submitFormData => {
	let url = '/ad/save';
    if(submitFormData.id){
        url = '/ad/update';
    }
    return post(url, submitFormData);
}

//删除
apis.delete = (_this, id, callback) => {
	_this.$confirm('是否删除?', '提示').then(() => {
        post('/ad/delete', {id:id}).then(d=>{
            _this.msg.success('删除成功!');
            callback(d);
        })
    });
}

//禁用或者启用
apis.enable = (_this, row, callback) => {
	let oldEnable = row.enable==0?1:0;
    let msg = row.enable==0?'是否禁用':'是否启用';
    _this.$confirm(msg, '提示').then(() => {
        post('/ad/doEnable', {id:row.id,enable:row.enable}).then(d=>{
            if(d.code!=0){
                row.enable = oldEnable;
                _this.msg.error(d.message);
            } else {
            	callback(d);
            }
        })
    }).catch(() => {
        row.enable = oldEnable;
    });
}

export default apis